import { defineStore } from 'pinia'
import { UserInfo } from '../interface/user'
import { Local } from '@/utils/storage'
import { reactive } from 'vue'
import { TOKEN } from '../constant/cacheKey'

export const useUserInfo = defineStore('userInfo', () => {
    const state = reactive<UserInfo>({
        token: '',
        id: '',
    })
    const setToken = (token: string) => {
        state.token = token
        Local.set(TOKEN, token)
    }
    const removeToken = () => {
        state.token = ''
        Local.remove(TOKEN)
    }

    return { state, setToken, removeToken }
})
